<?php 
    class ThongbaoController extends BaseController{
        //Return ra view cua fontend
        public function trangchu(){				
			$articles = DB::table('thongbao')
			->select('tieude','noidung','ngaytao','nguoitao','id')
			->paginate(6);
            return View::make('fontend.trangchu')->with(array('articles' => $articles));
        }
        public function chitietthongbao($id){				
			$article = DB::table('thongbao')
						->where('id', '=', $id)
						->first();
    		return View::make('fontend.chitietthongbao')->with(array('article' => $article));
        }
        //Backend
        public function index(){
            $filter_title = Input::get('title');
    		if($filter_title != '') {
				$articles = DB::table('thongbao')
					->whereRaw('thongbao.tieude like ?', 
						array('%'.$filter_title.'%'))
					->select('tieude','noidung','ngaytao','nguoitao','id')
					->paginate(10);
    		} else {    				
				$articles = DB::table('thongbao')
				->select('tieude','noidung','ngaytao','nguoitao','id')
				->paginate(10);
    		}
            return View::make('backend.thongbao.danhsach')->with(array('articles' => $articles));
        }
        public function add(){
            return View::make('backend.thongbao.add_content');
        }
        public function store()
    	{
    		$title = Input::get('title');
    		$fulltext = Input::get('content');   		
    		$createday   = Input::get('create');    
//    		// insert data in datase
    		$article = DB::table('thongbao')->insertGetId(
        		array('tieude' => $title,'noidung' => $fulltext,
        			 'ngaytao' => $createday, ));
    		return Redirect::to('admin/content');
    	}
        public function edit($id)
    	{
    	    $article = DB::table('thongbao')
						->where('id', '=', $id)
						->first();
    		return View::make('backend.thongbao.edit_content')->with(array('article' => $article));
    	}
        public function update($id)
    	{    		
    		$title = Input::get('title');    	
    		$fulltext = Input::get('content');
    		$createday   = Input::get('create');
			DB::table('thongbao')
            ->where('id', $id)
            ->update(array('tieude' => $title,'noidung' => $fulltext,
        			 'ngaytao' => $createday, ));
    		return Redirect::to('admin/content');
    	}
        public function destroy($id)
    	{	
    		$article = DB::table('thongbao')->where('id', '=', $id)->delete();
    
    		return Redirect::to('admin/content');
    	}
    }
?>